package com.example.demo.web;

import com.example.demo.web.module.School;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
// import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
// import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

// @Controller
@RestController
public class IndexController {

  @Autowired
  private School sc;

  /**
   * 该方法即支持get、post、put、delete、patch等多个方法
   */
  @RequestMapping(value = "/index")
  // @ResponseBody
  public String say() {
    return "Hello" + sc.getName() + sc.getWebsite();
  }

  /**
   * 只支持GET\POST请求
   */
  @RequestMapping(value = "/index1", method = { RequestMethod.GET, RequestMethod.POST })
  // @ResponseBody
  public Object index1() {
    return "index1 get\\post method";
  }

  /**
   * 只支持GET请求，通常用于查询操作
   */
  @GetMapping(value = "/index2")
  // @ResponseBody
  public Object index2() {
    return "index2 get method";
  }

  /**
   * 只支持POST请求，通常用于新增操作
   */
  @PostMapping(value = "/index3")
  // @ResponseBody
  public Object index3() {
    return "index3 post method";
  }

  /**
   * 只支持PUT请求，用于更新操作
   */
  @PutMapping(value = "/index4")
  public Object index4() {
    return "only put method";
  }

  @RequestMapping(value = "/index5", method = RequestMethod.PUT)
  public Object index5() {
    return "only put method";
  }

  /**
   * 只支持DELETE请求，用于删除操作
   */
  @DeleteMapping(value = "/index6")
  public Object index6() {
    return "only delete method";
  }

  @RequestMapping(value = "/index7", method = RequestMethod.DELETE)
  public Object index7() {
    return "only delete method";
  }
}
